#define  _CRT_SECURE_NO_WARNINGS 1
#include "SList.h"
struct SLTNode* mergeTwoLists1(struct SLTNode* list1, struct SLTNode* list2) {
    SLTNode* l1 = list1;
    SLTNode* l2 = list2;
    SLTNode* newnode = NULL;
    SLTNode* phead = newnode;
    if (l2 == NULL)
        return l1;
    if (l1 == NULL)
        return l2;
    while (l1 && l2) {
        if (l1->data < l2->data) {
            if (newnode == NULL) {
                newnode = phead = l1;
                newnode = newnode->next;
            }
            else {
                newnode = l1;
                newnode = newnode->next;
            }
            l1 = l1->next;
        }
        else {
            if (newnode == NULL) {
                newnode = phead = l2;
                newnode = newnode->next;
            }
            else {
                newnode = l2;
                newnode = newnode->next;
            }
            l2 = l2->next;
        }
    }
    if (l1) {
        newnode = l1;
    }
    if (l2) {
        newnode = l2;
    }
    return phead;
}


struct SLTNode* mergeTwoLists2(struct SLTNode* list1, struct SLTNode* list2) {
    SLTNode* l1 = list1;
    SLTNode* l2 = list2;
    SLTNode* newnode = NULL;
    SLTNode* phead = newnode;
    if (l2 == NULL)
        return l1;
    if (l1 == NULL)
        return l2;
    while (l1 && l2) {
        if (l1->data < l2->data) {
            if (newnode == NULL) {
                newnode = phead = l1;
            }
            else {
                newnode->next = l1;
                newnode = newnode->next;
            }
            l1 = l1->next;
        }
        else {
            if (newnode == NULL) {
                newnode = phead = l2;
            }
            else {
                newnode->next = l2;
                newnode = newnode->next;
            }
            l2 = l2->next;
        }
    }
    if (l1) {
        newnode->next = l1;
    }
    if (l2) {
        newnode->next = l2;
    }
    return phead;
}
void SlistTest01()
{
	SLTNode* plist1 = NULL;
	SLTNode* plist2 = NULL;
    SLTNode* p = NULL;
	SLTPushBack(&plist1, 1);
	SLTPushBack(&plist1, 2);
	SLTPushBack(&plist1, 4);

	SLTPushBack(&plist2, 1);
	SLTPushBack(&plist2, 3);
	SLTPushBack(&plist2, 4);
	/*
SLTPrint(plist);
	SLTNode* FindRet = SLTFind(plist, 1);*/

   p = mergeTwoLists2(plist1, plist2);
}


int main()
{
	SlistTest01();
	return 0;
}


